{% extends "base.html" %}

{% block content %}
<script type="text/javascript">

function modPassword(userp, id){
	var capa = document.getElementById("usr"+id);
	var form = document.createElement("form");
	var user = document.createElement("input");
	var oldPass = document.createElement("input");
	var newPass = document.createElement("input");
	var confPass = document.createElement("input");
	var submit = document.createElement("input");
	
	user.type="hidden";
	user.name = "userp";
	user.value = id;
	oldPass.type = "text";
	oldPass.name = "oldPass";
	oldPass.value = "Password antiguo";
	newPass.type = "text";
	newPass.name = "newPass";
	newPass.value = "Password nuevo";
	confPass.type = "text";
	confPass.name = "confPass";
	confPass.value = "confirmar Password nuevo";
	
	submit.type = "submit";
	submit.value = "Cambiar";
	
	form.action = "/setPassword/";
	form.method = "get";
	
	capa.appendChild(form);
	form.appendChild(user);
	form.appendChild(oldPass);
	form.appendChild(newPass);
	form.appendChild(confPass);
	form.appendChild(submit);
	
}

function modAtributo(userp, id, X){
	var capa = document.getElementById("usr"+id);
	var form = document.createElement("form");
	var user = document.createElement("input");
	var newAtributo = document.createElement("input");
	var tipo = document.createElement("input");
	var submit = document.createElement("input");
	
 	user.type="hidden";
	user.name = "userp";
	user.value = id;
	newAtributo.type = "text";
	newAtributo.name = "mod";
	
	if (X==1) {
		newAtributo.value = "Nombre nuevo";
		
	}else{
		newAtributo.value = "Email nuevo";
	}
	
	tipo.type = "hidden";
	tipo.name = "tipo"
	tipo.value = X;
	
	submit.type = "submit";
	submit.value = "Cambiar";
	
	form.action = "/setAtributo/";
	form.method = "get";
	
	capa.appendChild(form);
	form.appendChild(user);
	form.appendChild(newAtributo);
	form.appendChild(tipo);
	form.appendChild(submit); 
	
}

</script>

<div id="cabecera">
		<h1> Modificar atributos </h1>
		<h3> {{mensaje}}</h3>
</div>

{% for usr in users %}
<div id="usr{{usr.id}}">
		<p>{{usr}} 
		<a href="#" onclick="modPassword('{{usr}}', '{{usr.id}}')"> modificar password</a>
		<a href="#" onclick="modAtributo('{{usr}}', '{{usr.id}}',1)"> modificar nombre</a>
		<a href="#" onclick="modAtributo('{{usr}}', '{{usr.id}}',0)"> modificar email</a>
		</p>
</div>
{% endfor %}
 
{% endblock %}